package com.sinosoft.vaccinetoai.security.shiro;

import cn.hutool.crypto.SecureUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

/**
 * 自定义凭证匹配器
 * @author xzh
 * @date 2023-04-08 15:20
 * @since 1.0.0
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

    /**
     * 凭证比较匹配方法
     * @param token 认证时传入的信息
     * @param info 存储在库中的信息
     * @return boolean 是否匹配
     * @author xzh
     * @since 1.0.0
     */
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        String tokenCredentials = new String((char[]) token.getCredentials());
        Object accountCredentials = info.getCredentials();
        return equals(SecureUtil.md5(tokenCredentials), accountCredentials);
    }

}
